package com.leetcode.algorithm.y22.m06;

import java.util.ArrayList;
import java.util.List;

import com.leetcode.algorithm.common.Node;

/**
 * 589. N 叉树的前序遍历
 * 
 * https://leetcode.cn/problems/n-ary-tree-preorder-traversal/
 * 
 * @author jie.deng
 *
 */
class Question0589Solution01 {
	
	public List<Integer> preorder(Node root) {
		List<Integer> list = new ArrayList<>();
		preorder(root, list);
		return list;
	}

	private void preorder(Node root, List<Integer> list) {
		if (root == null) {
			return;
		}
		list.add(root.val);
		for (Node node : root.children) {
			preorder(node, list);
		}
	}
    
}